<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2018/11/30</title>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
    <script src="http://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<input type="text" placeholder="username" id="username"><br>
<input type="text" placeholder="username" id="password"><br>
<button id="login">登录</button>
<button id="test">测试</button>
<br>
</body>
<script>
    var username = document.getElementById('username');
    var password = document.getElementById('password');
    var login =document.getElementById('login');
    var test =document.getElementById('test');
    window.onload =function(){
        login.onclick=function(){
            var usernameValue= user.value;
            var passwordValue =password.value;
            $.ajax({
                method:'get',
                url:'http://localhost:8080/login',
                data: {
                     username:usernameValue,
                     password:passwordValue
                },
                success: function (data) {
                    console.log(data);
                },
                fail: function (error) {
                    console.log(error);
                }
            });
        };
        test.onclick=function(){
            $.ajax({
                method:'get',
                url:'http://localhost:8080/test',
                success: function (data) {
                    console.log(data);
                },
                fail: function (error) {
                    console.log(error);
                }
            });
        }
    }
</script>
</html>
